在 Day16 中,我們已經將 AI 模型部署到雲端。接下來的重點,就是如何把這些模型真正整合到應用程式裡,讓使用者能夠透過 前端、行動 App 或後端系統 直接調用模型 API。
模型部署
取得 API Endpoint 與憑證
測試呼叫 API
應用整合
項目 | Azure Managed Endpoint | Vertex AI Endpoints |
---|---|---|
建立方式 | Azure ML Studio 一鍵部署 / CLI | GCP Console / gcloud / SDK |
自動縮放 | 支援 Auto-scaling,根據需求調整計算資源 | 同樣支援 Auto-scaling,且可配置 GPU/TPU |
存取控管 | 與 Azure AD 整合,支援 RBAC、Private VNET | 與 IAM 整合,支援 API Key / Service Account |
整合 SDK | Python SDK、REST API、C#、Java | Python SDK、REST API、gRPC |
適用情境 | Microsoft 生態圈、Power Platform 整合 | 需要 TPU / Google 生態(BigQuery、Cloud Run) |
import requests
url = "https://<your-endpoint>.azurewebsites.net/score"
headers = {
"Authorization": "Bearer <your-token>",
"Content-Type": "application/json"
}
data = {"input_data": {"text": "Hello Azure AI!"}}
response = requests.post(url, headers=headers, json=data)
print("Prediction:", response.json())
from google.cloud import aiplatform
from google.cloud import aiplatform
# 初始化客戶端
aiplatform.init(project="your-project-id", location="us-central1")
endpoint = aiplatform.Endpoint("projects/<project-id>/locations/us-central1/endpoints/<endpoint-id>")
response = endpoint.predict(instances=[{"text": "Hello Vertex AI!"}])
print("Prediction:", response.predictions)
async function callAI() {
const response = await fetch("https://your-endpoint.com/score", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
},
body: JSON.stringify({ input_data: { text: "Hello from frontend!" } })
});
const result = await response.json();
console.log(result);
}
callAI();
典型的整合架構會是這樣:
[ Web 前端 / Mobile App / Backend ]
↓ (HTTPS)
[ API Gateway / Endpoint 認證 ]
↓
[ Azure Managed Endpoint / Vertex AI Endpoint ]
↓
[ 模型推論 (CPU/GPU/TPU) ]
↓
[ 回傳結果至應用程式 ]
Day17 我們正式走完 「模型部署 → API 化 → 應用整合」 這條路。
Azure Managed Endpoint 適合快速整合 Microsoft 生態(Power Apps、Teams、.NET 系統)。
Vertex AI Endpoints 適合需要高彈性、高效能(特別是 TPU、大規模推論)的場景。
👉 下一步(Day18),我們將不只停留在 API 呼叫,而是深入探討 Prompt Engineering 與最佳化技巧,讓模型輸出的結果更貼近需求。